<template>
	<view class="page">
		<view class="ss">
			<uni-easyinput v-model="name" placeholder="请输入订单名称" @change="change" clearable></uni-easyinput>
		</view>
		<view class="list">
			<u-list>
				<u-list-item v-for="(item, index) in orders" :key="index">
					<!-- <view @click="choose(item)"> -->
						<u-cell :title="item.name" :label="item.duetime" :value="item.status"  @click="choose(item)"></u-cell>
					<!-- </view> -->
				</u-list-item>
			</u-list>
		</view>
	</view>
</template>

<script>
	import {
		orders
	} from '@/api/common.js';
	export default {
		data() {
			return {
				name: '',
				orders: []
			}
		},
		onLoad: function(option) {
			this.getOrders()
		},
		methods: {
			getOrders() {
				orders({
					pname: this.name
				}).then(res => {
					console.log(res);
					this.orders = res;
				}).catch(err => {
					console.log(err);
					uni.showToast({
						title: err,
						icon: 'none'
					});
				})
			},
			change() {
				console.log('查詢...')
				this.getOrders();
			},
			choose(e) {
				console.log('选择...' + JSON.stringify(e))
				uni.setStorageSync('order', e);
				uni.$emit('order', e)
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ss {
		width: 80vw;
		margin-left: 10vw;
	}

	.list {
		margin-top: 1vh;
	}
</style>